package com.greenantmall.activity;

import java.util.ArrayList;
import java.util.List;

import com.avos.avoscloud.AVUser;
import com.greenantmall.R;
import com.greenantmall.AntHomeApplication;
import com.greenantmall.adapter.MyFavListAdapter;
import com.greenantmall.bean.Goods;
import com.greenantmall.bean.GoodsList;
import com.greenantmall.service.RetrieveDataAsyn;
import com.greenantmall.service.RetrieveDataListener;
import com.greenantmall.utils.iLog;
import com.lsarah.utils.SystemBarTintManager;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MyFavActivity extends BaseActivity
{
    private final static String TAG = "MyFavActivity";
    List<Goods> list = new ArrayList<Goods>();
    MyFavListAdapter myFavListAdapter;

    private TextView noFavHint;
    private ListView favlist;
    
    private  RelativeLayout  nodataView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        SystemBarTintManager.setContentView(this, R.layout.myfav, getResources().getColor(R.color.green));
        favlist = (ListView) this.findViewById(R.id.favlist);
        noFavHint = (TextView) this.findViewById(R.id.noFavHint);
        nodataView = (RelativeLayout) this.findViewById(R.id.nodataView);

        myFavListAdapter = new MyFavListAdapter(list, this);
        favlist.setAdapter(myFavListAdapter);
        RetrieveDataAsyn.getInstance().getFavGoodsList(AVUser.getCurrentUser().getObjectId(),
            AntHomeApplication.sectionNum, 1, new RetrieveDataListener()
            {

                @Override
                public void dataRetrieved(int requestId, Object data)
                {
                    GoodsList goodsList = ((GoodsList) data);

                    noFavHint.setVisibility(View.INVISIBLE);
                    favlist.setVisibility(View.VISIBLE);

                    if (goodsList != null)
                    {
                        iLog.d(TAG, "myFavListAdapter list size:" + goodsList.getGoodList().size());
                        list.clear();
                        list.addAll(goodsList.getGoodList());
                        myFavListAdapter.notifyDataSetChanged();
                        if (list.size() == 0)
                        {
                            noFavHint.setVisibility(View.VISIBLE);
                            favlist.setVisibility(View.INVISIBLE);
                        }
                    } else
                    {
                        noFavHint.setVisibility(View.VISIBLE);
                        favlist.setVisibility(View.INVISIBLE);
                    }
                    nodataView.setVisibility(View.INVISIBLE);
                }
            });

    }
    
    public void refreshView(){
        noFavHint.setVisibility(View.VISIBLE);
        favlist.setVisibility(View.INVISIBLE);
    }

    public void goBack(View view)
    {
        finish();
    }
}
